package controllers

import (
	"news/common/response"
	"news/logic"
	"strconv"

	"github.com/gin-gonic/gin"
)

func PostPreviousHandler(c *gin.Context) {
	idStr := c.Query("id")
	parseInt, err := strconv.ParseInt(idStr, 10, 64)
	if err != nil {
		response.ResponseErr(c, response.CodeInvalidParam)
		return
	}

	prevPost, nextPost, err := logic.GetPrevAndNextPost(parseInt)
	if err != nil {
		response.ResponseErr(c, response.CodeServerBusy)
		return
	}
	if prevPost.Id == 0 {
		prevPost.Title = "没有数据了"
	}
	if nextPost.Id == 0 {
		nextPost.Title = "没有数据了"
	}
	var m map[string]interface{} = make(map[string]interface{}, 10)
	m["prevPost"] = prevPost
	m["nextPost"] = nextPost
	response.ResponseSuccess(c, m)

}
